<?php
/* 
 * ********* CVS HEADER ********* 
 * 
 * $RCSfile: admusergroupaff.php,v $ 
 * $Date: 2005/08/29 13:26:09 $ 
 * $Revision: 1.2 $ 
 * 
 * ********* CVS HEADER ********* 
 */
require_once ("module/TPLN/TPLN.php");
$TPLN = new TPLN;

$TPLN -> Open($op_basepath."tpl/admusergroupaff.html");
$TPLN -> IncludeFile("header", "environnement/".$session["environnement"]."/header.php");
$TPLN -> IncludeFile("footer", "environnement/".$session["environnement"]."/footer.php");

require_once(get_path_module("admin")); 
$pc = new panneau_controle(); 
$pc->calculRubriqueParFonction('admusergest'); 
$TPLN->Parse("panneau_controle",$pc->retourneEntete());

$query ="SELECT * FROM groupe_management WHERE id_groupe='". $session["id_groupe"]. "'";
$query.=" AND id_management='$argid'";
$result=rportalrequete($query) or die ("ERREUR 0146");
if($row=rportalligne($result)) {
	/* Do nothing */
} else {
	include("session/erreur404.php");
	exit();
}

$L_bloc="groupdesc";

$query ="SELECT groupe.id AS id_groupe,groupe.nom AS nom,groupe.description AS description,";
$query.=" environnement.nom AS environnement FROM groupe,environnement";
$query.=" WHERE groupe.id_environnement=environnement.id AND groupe.id='$argid'";
$query.=" GROUP BY groupe.id";
$result=rportalrequete($query) or die ("ERREUR 0147");
if($row=rportalligne($result))
{
	$TPLN -> Parse($L_bloc.".nom", $row["nom"]);
	$TPLN -> Parse($L_bloc.".environnement", $row["environnement"]);
	$TPLN -> Parse($L_bloc.".description", $row["description"]);
} else {
	$TPLN -> EraseBloc($L_bloc);
}

$groupdefseq = $rportalparams->get_value("RPORTAL","groupe.sequenceur");
$groupdefarch= $rportalparams->get_value("RPORTAL","groupe.archive");
$groupdefsupp= $rportalparams->get_value("RPORTAL","groupe.corbeille");

$L_bloc="affgroup";

if(($groupdefseq!=$argid)&&($groupdefsupp!=$argid)&&($groupdefarch!=$argid)) {
	$query ="SELECT * from groupe,groupe_management WHERE groupe.id!='$argid'";
	$query.=" AND groupe.id!='$groupdefsupp' AND groupe.id!='$groupdefarch'";
	$query.=" AND groupe.id!='$groupdefseq'";
	$query.=" AND groupe_management.id_groupe='" .$session["id_groupe"] ."'";
	$query.=" AND groupe_management.id_management=groupe.id";
	$query.=" GROUP BY groupe.id ORDER BY groupe.nom";
	$result=rportalrequete($query) or die ("ERREUR 0148");
	$L_subbloc = $L_bloc.".mouvgroups";
	$L_nbElem = 0;
	while($row=rportalligne($result)) {
		$TPLN -> Parse($L_subbloc.".id", $row["id"]); 
		$TPLN -> Parse($L_subbloc.".nom", $row["nom"]);
		$L_nbElem++; 
		$TPLN -> Loop($L_subbloc);
	}
	if (0==$L_nbElem) {
		/* No line, erase bloc */
		$TPLN -> EraseBloc($L_subbloc);
	}

	$query="SELECT id,nom FROM sequence ORDER BY nom ASC";
	$result=rportalrequete($query) or die ("ERREUR 0148");
	$L_subbloc = $L_bloc.".mouvseqs";
	$L_nbElem = 0;
	while($row=rportalligne($result)) {
		$TPLN -> Parse($L_subbloc.".id", $row["id"]); 
		$TPLN -> Parse($L_subbloc.".nom", $row["nom"]);
		$L_nbElem++; 
		$TPLN -> Loop($L_subbloc);
	}
	if (0==$L_nbElem) {
		/* No line, erase bloc */
		$TPLN -> EraseBloc($L_subbloc);
	}
	
} else {
	$TPLN -> EraseBloc($L_bloc);
}
$TPLN -> Parse("argid", $argid); 

$query="SELECT * FROM utilisateur WHERE id_groupe='$argid'";
$result=rportalrequete($query) or die ("ERREUR 0149");
$class="liste_impaire";
$L_bloc="users";
$L_nbElem = 0;
while($row=rportalligne($result)) {
	$TPLN -> Parse($L_bloc.".class", $class);
	if($class!="liste_impaire") {
		$class="liste_impaire";
	} else {
		$class="liste_paire";
	}
	$TPLN -> Parse($L_bloc.".user_id", $row["id"]);
	$TPLN -> Parse($L_bloc.".user_nom", $row["nom"]);
	$TPLN -> Parse($L_bloc.".user_prenom", $row["prenom"]);
	
	if($groupdefarch!=$argid) {
		$L_subbloc=$L_bloc.".withlink";
		$TPLN -> EraseBloc($L_bloc.".withoutlink");
		$TPLN -> Parse($L_subbloc.".user_id", $row["id"]);
	} else {
		$L_subbloc=$L_bloc.".withoutlink";
		$TPLN -> EraseBloc($L_bloc.".withlink");
	}
	$TPLN -> Parse($L_subbloc.".user_login", $row["login"]);
	$TPLN -> Loop($L_bloc);	
	$L_nbElem++;
}
if (0==$L_nbElem) {
	/* No line, erase bloc */
	$TPLN -> EraseBloc($L_bloc);
}

$TPLN->Write();

?>